﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Ewk.Runtime.Serialization.PositionBased;

namespace Ewk.Runtime.Serialization.UnitTests.PositionBased
{
    /// <summary>
    /// Summary description for DatarecordLengthCriteriumTests
    /// </summary>
    [TestClass]
    public class DatarecordLengthCriteriumTests
    {
        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void DatarecordLengthCriterium_has_value_zero_for_the_None_option()
        {
            const int value = (int)DatarecordLengthCriterium.None;

            Assert.AreEqual(0, value);
        }

        [TestMethod]
        public void
        DatarecordLengthCriterium_can_be_used_as_flags_so_that_values_can_be_combined_and_separatly_identified()
        {
            const DatarecordLengthCriterium value = DatarecordLengthCriterium.EqualsDefinition | DatarecordLengthCriterium.GreaterThanDefinition;

            Assert.IsTrue((value & DatarecordLengthCriterium.EqualsDefinition) == DatarecordLengthCriterium.EqualsDefinition);
            Assert.IsTrue((value & DatarecordLengthCriterium.GreaterThanDefinition) == DatarecordLengthCriterium.GreaterThanDefinition);
            Assert.IsFalse((value & DatarecordLengthCriterium.SmallerThanDefinition) == DatarecordLengthCriterium.SmallerThanDefinition);
        }

        [TestMethod]
        public void
        DatarecordLengthCriterium_can_have_predefined_combinations()
        {
            Assert.AreEqual(DatarecordLengthCriterium.GreaterOrEqualToDefinition, DatarecordLengthCriterium.EqualsDefinition | DatarecordLengthCriterium.GreaterThanDefinition);
            Assert.AreEqual(DatarecordLengthCriterium.SmallerOrEqualToDefinition, DatarecordLengthCriterium.EqualsDefinition | DatarecordLengthCriterium.SmallerThanDefinition);

            Assert.IsTrue((DatarecordLengthCriterium.GreaterOrEqualToDefinition & DatarecordLengthCriterium.EqualsDefinition) == DatarecordLengthCriterium.EqualsDefinition);
            Assert.IsTrue((DatarecordLengthCriterium.GreaterOrEqualToDefinition & DatarecordLengthCriterium.GreaterThanDefinition) == DatarecordLengthCriterium.GreaterThanDefinition);
            Assert.IsFalse((DatarecordLengthCriterium.GreaterOrEqualToDefinition & DatarecordLengthCriterium.SmallerThanDefinition) == DatarecordLengthCriterium.SmallerThanDefinition);
        }

        [TestMethod]
        public void
        DatarecordLengthCriterium_All_is_the_definition_for_all_of_the_enum_values()
        {
            var values = Enum.GetValues(typeof (DatarecordLengthCriterium));

            foreach (var value in values)
            {
                var enumValue = (DatarecordLengthCriterium) value;
                Assert.IsTrue((DatarecordLengthCriterium.All & enumValue) == enumValue);
            }
        }
    }
}
